package vn.com.khangpn.rest;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class TestRestful {

	@RequestMapping(value = "/get/{name}", method=RequestMethod.POST)
	public @ResponseBody Person getPerson(@PathVariable String name) {
		Person person = new Person();
		person.setAge(10);
		person.setName(name);
		return person;
	}
	
	@RequestMapping(value = "/get/all", method=RequestMethod.GET)
	public @ResponseBody List<Person> getAllPerson() {
		List<Person> persons = new ArrayList<TestRestful.Person>();
		for(int i = 0; i < 100; i++) {
			Person person = new Person();
			person.setAge(i*10);
			person.setName("Khangpn " + (i+1));
			persons.add(person);
		}
		
		try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return persons;
	}
	
	public class Person implements Serializable {
		
		private static final long serialVersionUID = 1L;
		
		private String name;
		private int age;
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public int getAge() {
			return age;
		}
		public void setAge(int age) {
			this.age = age;
		}
	}
	
}
